layui.use(['laydate', 'layer'], function () {
    var $ = layui.jquery, laydate = layui.laydate;
    laydate.render({
        elem: '#my-n1'
        , theme: 'molv'
        , position: 'static'
        , format: 'yyyy/MM/dd'
        , change: function (value, date, endDate) {
            $.ajax({
                url: "/uc/user/ajax/list",
                type: "GET",
                dataType: "json",
                data: {"date": value},
                error: function () {
                    console.log("请求失败！");
                },
                success: function (data) {
                    var html = "<div class='layui-custom-li12 custom-table'>" +
                        "<div class='layui-custom-li1'>优先级</div>" +
                        "<div class='layui-custom-li8'>日程标题</div>" +
                        "<div class='layui-custom-li3'>日程类别</div></div>";
                    if (null != data && "" != data) {
                        var dataList = data.dataList;
                        if (null != dataList && dataList.length > 0) {
                            for (var i = 0; i < dataList.length; i++) {
                                var info = "<div class='layui-custom-li1'>" +
                                    "<span class='layui-custom-span layui-custom-span8 layui-custom-green'></span>" +
                                    "</div>";
                                if (dataList[i].rcjb == '3') {
                                    info = "<div class='layui-custom-li1'>" +
                                        "<span class='layui-custom-span layui-custom-span8 layui-custom-red'></span>" +
                                        "</div>";
                                }
                                if (dataList[i].rcjb == '2') {
                                    info = "<div class='layui-custom-li1'>" +
                                        "<span class='layui-custom-span layui-custom-span8 layui-custom-yellow'></span>" +
                                        "</div>";
                                }
                                html = html + "<div class='layui-custom-li12 custom-open custom-onclick' content='" + dataList[i].id + "'>" +
                                    info +
                                    "<div class='layui-custom-li8'>" + dataList[i].title +
                                    "</div><div class='layui-custom-li3'>" + dataList[i].lbmc +
                                    "</div></div>";
                            }
                        }
                    }
                    $(".custom-day").html(html);
                    $(".custom-open").off("click").on("click", function () {
                        var id = $(this).attr("content");
                        layer.open({
                            title: "日程详情",
                            type: 2,
                            area: ['80%', '80%'],
                            fixed: true, //不固定
                            maxmin: true,
                            content: '/uc/user/'+id+'/entity'
                        });
                    });
                }
            });
        }
    });
    $(".custom-btn-add").on("click", function () {
        layer.open({
            title: "添加个人日程",
            type: 2,
            area: ['80%', '80%'],
            fixed: true, //不固定
            maxmin: true,
            content: '/uc/user/add'
        });
    });
    $(".custom-btn-query").on("click", function () {
        window.location.replace("/uc/user/query/list");
    });
    $(".custom-btn-add-role").on("click", function () {
        layer.open({
            title: "日程安排",
            type: 2,
            area: ['80%', '80%'],
            fixed: true, //不固定
            maxmin: true,
            content: '/uc/user/add/tag'
        });
    });
    $(".custom-open").off("click").on("click", function () {
        var id = $(this).attr("content");
        layer.open({
            title: "日程详情",
            type: 2,
            area: ['80%', '80%'],
            fixed: true, //不固定
            maxmin: true,
            content: '/uc/user/'+id+'/entity'
        });
    });
});